import com.beans.UserBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/7/11
 * \* Time: 20:56
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class test {
    public static void main(String[] args) {
//        //1.得到上下文对象
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        //2.通过上下文对象提供的方法，获取我们自己需要使用的bean对象
//        UserBean user = (UserBean) context.getBean("user");//需要强转
//        //3.调用对象里面的方法
//        user.sayHi("aaa");

        //1.使用BeanFactory方法来获取上下文对象
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
        //2.获取Bean
        UserBean userBean = beanFactory.getBean("user",UserBean.class);
        //3.使用Bean
        userBean.sayHi("aaa");
    }
}
